import pytest

from api.ihrmLoginApi import IhrmLoginApi
from commen.assert_tools import assert_methods
from commen.read_json_tools import read_json_file

from config import BASE_DIR


class TestIhrmLogin:
    filename = BASE_DIR + "/data/login_data.json"
    #  定义测试方法  参数化
    @pytest.mark.parametrize("desc,request_data,status_code,success,code,message",read_json_file(filename)) # 装饰器 两个参数
    def test_login(self,desc,request_data,status_code,success,code,message):
        resp = IhrmLoginApi.login(request_data)  # 调用自己封装的接口
        assert_methods(resp, status_code, success, code, message) # 断言


    # # 定义测试方法 - 登陆成功
    # def test01_login_ok(self):
    #     my_json = {"mobile": "13800000002", "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("登陆成功:",resp.json())
    #     # 调用assert_methods方法 优化代码
    #     assert_methods(resp,200,True,10000,"操作成功")
    #
    #     # assert 200 == resp.status_code
    #     # assert True is resp.json().get("success")
    #     # assert 10000 == resp.json().get("code")
    #     # assert "操作成功" in resp.json().get("message")
    #
    # def test02_moblie_no_exists(self):
    #     my_json = {"mobile": "13800012302", "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("手机号未注册:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test03_code_err(self):
    #     my_json = {"mobile": "13800012302", "password": "123556"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("密码错误:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test04_moblie_isNone(self):
    #     my_json = {"mobile": None, "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("手机号为空:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test05_moblie_num12(self):
    #     my_json = {"mobile": "123456123456", "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("手机号为12位:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test06_moblie_num10(self):
    #     my_json = {"mobile": "1234561234", "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("手机号为10位:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test07_moblie_num10(self):
    #     my_json = {"mobile": "13800*00002", "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("手机号含有特殊字符:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    # def test08_code_isNone(self):
    #     my_json = {"mobile": "13800000002", "password": None}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("密码为空:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test09_code_nom1(self):
    #     my_json = {"mobile": "13800000002", "password": "1"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("密码1位:", resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test10_code_nom100(self):
    #     my_json = {"mobile": "13800000002", "password": "123467890123467890123467890123467890123467890123467890123467890123467890123467890123467890"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("密码100位:", resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test11_code_err01(self):
    #     my_json = {"mobile": "13800000002", "password": "123*56"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("密码含特殊字符:", resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test12_many_param(self):
    #     my_json = {"mobile": "13800000002", "password": "123456","abc":"123"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("多参(多出abc参数,值123):",resp.json())
    #
    #     assert_methods(resp,200,True,10000,"操作成功")
    #
    #
    #
    # def test13_lack_param(self):
    #     my_json = { "password": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("少参(缺少-mobile):", resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
    #
    #
    # def test14_no_param(self):
    #     my_json = None
    #     resp = IhrmLoginApi.login(my_json)
    #     print("无参:", resp.json())
    #
    #     assert_methods(resp,200,False,99999,"抱歉，系统繁忙，请稍后重试")
    #
    #
    # def test15_param_err(self):
    #     my_json = {"mobile": "13800000002", "word": "123456"}
    #     resp = IhrmLoginApi.login(my_json)
    #     print("错误参数:password错写成pwd:",resp.json())
    #
    #     assert_methods(resp,200,False,20001,"用户名或密码错误")
